/**
 * Created with Intellij IDEA.
 * Description:
 * User: Zguoxu
 * Date: 2025-02-20
 * Time: 14:14
 */
public class Test {


    //虚拟机栈：放局部变量
    //堆：一般用来存储对象
    public static void move(char pos1, char pos2) {
        System.out.println(pos1 + " -> " + pos2);
    }

    //第一个参数 盘子数量
    //第二个参数 起始位置
    //第三个参数 中转位置
    //第四个参数 目的位置

    public static void hanNoi(int n, char pos1, char pos2, char pos3) {
        if(n == 1) {
            move(pos1, pos3);
        }else {
            hanNoi(n - 1, pos1, pos3, pos2);
            move(pos1, pos3);
            hanNoi(n - 1, pos2, pos1, pos3);
        }
    }

    public static void main(String[] args) {
        //汉诺塔
        hanNoi(1,'A','B','C');
        System.out.println("------");
        hanNoi(2,'A','B','C');
        System.out.println("------");
        hanNoi(3,'A','B','C');

    }

    public static int max2(int a, int b) {
        //求两个数最大值
        return a > b ? a : b;
    }

    public static int max3(int a, int b, int c) {
        //求三个数的最大值
        int max = max2(a, b);
        return max2(max, c);
    }

    public static int fac(int n) {
        //求 n 的阶乘
        if(n == 1) {
            return 1;
        }else {
            return n * fac(n - 1);
        }
    }

    public static int facSum(int n) {
        //求阶乘和
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int flag = 1;
            for (int j = 1; j <= i; j++) {
                flag *= j;
            }
            sum += flag;
        }
        return sum;
    }

    public static int fib(int n) {
        //求斐波那契
        int f1 = 0;
        int f2 = 1;
        int f3 = 0;
        if(n == 1) {
            return f1;
        }else if(n == 2) {
            return f2;
        }
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    public static int sum(int a, int b) {
        return a + b;
    }

    public static double sum(double a, double b, double c) {
        return a + b + c;
    }

    public static int max(int a, int b) {
        return a > b ? a : b;
    }

    public static double max(double a, double b, double c) {
        double max = a > b ? a : b;
        return max > c ? max : c;
    }




    public static void main1(String[] args) {
        System.out.println(max3(8,5,9));

        System.out.println(fac(5));

        System.out.println(facSum(5));

        System.out.println(fib(1));
        System.out.println(fib(2));
        System.out.println(fib(3));
        System.out.println(fib(4));
        System.out.println(fib(5));
        System.out.println(fib(6));
        System.out.println(fib(7));
        System.out.println(fib(8));

        System.out.println(sum(2.3, 3.3, 4.5));

        System.out.println(max(5.6, 9.8, 9.896));

    }
}
